if (SERVER) then
 	AddCSLuaFile("shared.lua");
end;

if (CLIENT) then
	SWEP.PrintName 		= "SPAS 12 Shotgun";
	SWEP.Instructions	= "Left click to shoot.";

	SWEP.Slot			= 2;
	SWEP.SlotPos		= 1;
	SWEP.ViewModelFlip 	= false;
	SWEP.DrawAmmo 		= false;
	SWEP.ViewModelFOV	= 62;
end;

SWEP.Base = "leaf_weapon_base";

SWEP.ViewModel			= Model("models/weapons/v_shotgun.mdl");
SWEP.WorldModel			= Model("models/weapons/w_shotgun.mdl");
SWEP.Primary.Sound		= Sound("Weapon_Shotgun.Single");

SWEP.Primary.Recoil			= 0.5;
SWEP.Primary.Cone			= 0.1;
SWEP.Primary.Damage			= 4;
SWEP.Primary.NumShots		= 9;

SWEP.Primary.ClipSize		= 6;
SWEP.Primary.DefaultClip 	= 6;
SWEP.Primary.Ammo 			= "buckshot";
SWEP.Primary.Delay 			= 1;
SWEP.Primary.Automatic 		= false;

SWEP.IronSightPos = Vector(-9, -5, 3);
SWEP.IronSightAng = Vector(-.5, -1, 0);

SWEP.HolsteredPos = Vector(10.8, -5, -2);
SWEP.HolsteredAng = Vector(-5.0, 50, 0);

SWEP.HoldType = "shotgun";

SWEP.resetReloading = true;
SWEP.Reloading = false;

function SWEP:Reload()
 	if (self.Reloading) then return; end;
	
	if (self.Weapon:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0) then
		self.Weapon:SetVar("reloadtimer", CurTime() +0.5);
		self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START);
		self.Owner:SetAnimation(PLAYER_RELOAD);
		
		if (SERVER) then
			self.Owner:EmitSound("weapons/shotgun/shotgun_reload" .. math.random(1, 3) .. ".wav");
		end;
		
		self.Reloading = true;
	end;
end;

function SWEP:Think()	
	if (self.Reloading) then
		if (self.Weapon:GetVar("reloadtimer") < CurTime()) then 
			if (self.Weapon:Clip1() >= self.Primary.ClipSize) then
				self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH);

				if (SERVER) then
					self.Owner:EmitSound("weapons/shotgun/shotgun_cock.wav");
				end;
				
				self.Reloading = false;
				return;
			end;

			self.Weapon:SetVar("reloadtimer", CurTime() +0.5);
			self.Weapon:SendWeaponAnim(ACT_VM_RELOAD);
			
			if (SERVER) then
				self.Owner:EmitSound("weapons/shotgun/shotgun_reload" .. math.random(1, 3) .. ".wav");
			end;
			
			self.Owner:RemoveAmmo(1, self.Primary.Ammo, false);
			self.Weapon:SetClip1(self.Weapon:Clip1() +1);
		end;
 	end;
end;